import { getMsbdListApi, addMsbdListApi, editMsbdListApi, deleteMsbdListApi } from '@/api/audit/index';
const state = () => {
    return {
        msbdList: [],
        classifyList: [],
        total: 0
    }
}

const mutations = {
    SET_LIST(state, data) {
        state.msbdList = data.data
        state.classifyList = data.classify
        state.total = data.total
    }
}

const actions = {
    async getMsbdList({ commit }, params) {
        let data = await getMsbdListApi(params)
        commit("SET_LIST", data)
    },
    async addMsbdList({ dispatch, rootState, state }, form) {
        let type = state.classifyList.filter(v => {
            if (v.id == form.cid) {
                return v.name
            }
        })[0].name
        await addMsbdListApi({ ...form, author: rootState.users.userInfo.name, type })
        dispatch("getMsbdList")
    },
    async editMsbdListApi({ dispatch }, form) {
        await editMsbdListApi(form)
        dispatch("getMsbdList")
    },
    async deleteMsbdList({ dispatch }, form) {
        await deleteMsbdListApi(form)
        dispatch("getMsbdList")
    }
}

const getters = {

}

export {
    state,
    mutations,
    actions,
    getters
}